<link rel="stylesheet" href="/static/admin/bootstrap-table/bootstrap-table.css">
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>仪表盘</h2>
        <ol class="breadcrumb">
            <li class="breadcrumb-item">
                <a href="/">首页</a>
            </li>
            <li class="breadcrumb-item">
                <a href="/admin">后台</a>
            </li>
            <li class="breadcrumb-item active">
                <strong>网站概要</strong>
            </li>
        </ol>
    </div>
</div>
<div class="wrapper wrapper-content">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox ">
                    <div class="ibox-content text-center p-md">
                        <h2 class="m-b-xxs"><span
                                    class="text-navy">目前有 {{tn "article"}} 篇文章, 并有 {{tn "comment"}} 条关于你的评论在 {{tn "category"}} 个分类中.</span>
                        </h2><br/>
                        <p>点击下面的链接快速开始:</p>
                        <span class="simple_tag"><a href="/admin/article/add">撰写新文章</a></span>
                        <span class="simple_tag"><a href="/admin/page/add">撰写新页面</a></span>
                        <span class="simple_tag"><a href="/admin/setting/website">系统设置</a></span>
                        <span class="simple_tag"><a href="/admin/style">主题设置</a></span>
                        <span class="simple_tag"><a href="/admin/comment">评论管理</a></span>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-4">
                <div class="ibox ">
                    <div class="ibox-title">
                        <h5>最近发布的文章</h5>
                    </div>
                    <div class="ibox-content inspinia-timeline no-padding">
                        {{with $article := na 5}}
                            {{range $article}}
                                <div class="timeline-item">
                                    <div class="row">
                                        {{with $time := dt .Renew}}
                                            <div class="col-3 date">
                                                <i class="fa fa-file-text"></i>
                                                {{$time.ymd}}
                                                <br>
                                                <small class="text-navy">{{$time.hms}}</small>
                                            </div>
                                        {{end}}
                                        <div class="col-7 content">
                                            <p class="m-b-xs"><strong><a itemprop="url"
                                                                         href="/article/{{.Name}}">{{.Title}}</a></strong>
                                            </p>
                                            <p>
                                                {{with $summary := markdown .Summary}}
                                                    {{str2html $summary }}
                                                {{end}}
                                            </p>
                                        </div>
                                    </div>
                                </div>
                            {{end}}
                        {{end}}
                    </div>
                </div>
            </div>
            <div class="col-lg-4">
                <div class="ibox ">
                    <div class="ibox-title">
                        <h5>最近得到的回复</h5>
                    </div>
                    <div class="ibox-content no-padding">
                        <ul class="list-group">
                            {{with $comment := nc 8 false}}
                                {{range $comment}}
                                    <li class="list-group-item">
                                        <p><a class="text-info" href="mailto:{{.Email}}">@{{.Name}}</a> : {{.Content}} -
                                            《<a href="/article/{{itu .Aid}}#comment-{{.Id}}">{{gafc .Aid "title"}}</a>》
                                        </p>
                                        <small class="block text-muted"><i
                                                    class="fa fa-clock-o"></i> {{tsc .Date false}}</small>
                                    </li>
                                {{end}}
                            {{end}}
                        </ul>
                    </div>
                </div>
            </div>
            <div class="col-lg-4">
                <div class="ibox ">
                    <div class="ibox-title">
                        <h5>官方最新日志</h5>
                    </div>
                    <div class="ibox-content">
                        <div class="table-responsive">
                            <table class="table table-hover issue-tracker">
                                <tbody>
                                {{with $changelog := changelog}}
                                    {{range $changelog.Version}}
                                        <tr>
                                            <td>
                                                <span class="label {{.Level}}">{{.Type}}</span>
                                            </td>
                                            <td class="issue-info">
                                                <a href="#">
                                                    {{.Title}}
                                                </a>

                                                <small>
                                                    {{.Commit}}
                                                </small>
                                            </td>
                                            <td>
                                                {{.Committer}}
                                            </td>
                                            <td>
                                                {{.Date}}
                                            </td>

                                            <td class="text-right">
                                                <button class="btn btn-white btn-xs"><a href="{{.Tag}}">Tag</a></button>
                                            </td>
                                        </tr>
                                    {{end}}
                                {{end}}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/static/admin/bootstrap-table/bootstrap-table.js"></script>
<script src="/static/admin/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
<script src="/static/admin/layer/layer.js"></script>
<script>
    $('#article-list').bootstrapTable({
        url: '/api/article/list',
        responseHandler: responseHandler,
        columns: [{
            field: 'Id',
            title: 'ID'
        }, {
            field: 'Title',
            title: '标题'
        }, {
            field: 'Author',
            title: '作者'
        }, {
            field: 'Name',
            title: '分类'
        }, {
            field: 'Tags',
            title: '标签'
        }, {
            field: 'Renew',
            title: '更新时间'
        }, {
            field: 'Option',
            title: '操作',
            align: 'center',
            formatter: operateFormatter,
            events: "operateEventsArticle",
        }],
        pagination: true,   //开启分页功能
        pageSize: 10,        //每页显示条数
    });

    $('#category-list').bootstrapTable({
        url: '/api/article/category/list',
        responseHandler: responseHandler,
        columns: [{
            field: 'Id',
            title: 'ID'
        }, {
            field: 'Name',
            title: '名称'
        }, {
            field: 'Key',
            title: '标识'
        }, {
            field: 'Description',
            title: '描述'
        }, {
            field: 'Option',
            title: '操作',
            align: 'center',
            formatter: operateFormatter,
            events: "operateEventsCategory",
        }],
    });

    function responseHandler(res) {
        return res.data;
    }

    function operateFormatter(value, row, index) {
        return [
            '<div class="operate-group">',
            '<a class="update layui-layer-btn0" href="#">修改</a>',
            '<a class="delete layui-layer-btn0" href="#">删除</a>',
            '</div>'
        ].join('');
    }

    // 定义layer主题名称
    layer.config({
        skin: 'layer-class'
    });
    window.operateEventsArticle = {
        'click .update': function (e, value, row, index) {
            self.location = '/admin/article/update?id=' + row.Id;
        },
        'click .delete': function (e, value, row, index) {
            layer.confirm('确定删除？', function (index) {
                $.get("/api/article/delete?id=" + row.Id, function (res) {
                    if (res.Error === 0) {
                        layer.open({
                            title: res.Title
                            , content: res.Msg,
                            yes: function (index) {
                                window.location.href = "/admin/article";
                                layer.close(index); //如果设定了yes回调，需进行手工关闭
                            }
                        });
                    } else {
                        layer.msg(res.Title + res.Msg, {
                            icon: 2,
                            shade: [0.8, '#393D49'], // 透明度  颜色
                            time: 2000
                        });
                    }
                }, "json");
                layer.close(index);
            });
        }
    };
    window.operateEventsCategory = {
        'click .update': function (e, value, row, index) {
            layer.open({
                type: 2,
                title: '修改分类信息',
                shadeClose: true,
                shade: 0.8,
                area: ['380px', '90%'],
                content: '/admin/article/category/update?id=' + row.Id //iframe的url
            });
        },
        'click .delete': function (e, value, row, index) {
            layer.confirm('确定删除？', function (index) {
                $.get("/api/article/category/delete?id=" + row.Id, function (res) {
                    if (res.Error === 0) {
                        layer.open({
                            title: res.Title
                            , content: res.Msg,
                            yes: function (index) {
                                window.location.href = "/admin/article/category";
                                layer.close(index); //如果设定了yes回调，需进行手工关闭
                            }
                        });
                    } else {
                        layer.msg(res.Title + res.Msg, {
                            icon: 2,
                            shade: [0.8, '#393D49'], // 透明度  颜色
                            time: 2000
                        });
                    }
                }, "json");
                layer.close(index);
            });
        }
    };
</script>